﻿using System;
using System.Collections.Generic;
using GeoAPI.Geometries;
using NetTopologySuite.Utilities;

namespace NetTopologySuite.Planargraph
{
	public class Node : GraphComponent
	{
		public static IList<DirectedEdge> GetEdgesBetween(Node node0, Node node1)
		{
			HashSet<DirectedEdge> hashSet = new HashSet<DirectedEdge>(Caster.Cast<DirectedEdge>(DirectedEdge.ToEdges(node0.OutEdges.Edges)));
			IList<Edge> inputs = DirectedEdge.ToEdges(node1.OutEdges.Edges);
			hashSet.ExceptWith(Caster.Cast<DirectedEdge>(inputs));
			return new List<DirectedEdge>(hashSet);
		}

		public Node(Coordinate pt) : this(pt, new DirectedEdgeStar())
		{
		}

		public Node(Coordinate pt, DirectedEdgeStar deStar)
		{
			this.pt = pt;
			this.deStar = deStar;
		}

		public Coordinate Coordinate
		{
			get
			{
				return this.pt;
			}
		}

		public void AddOutEdge(DirectedEdge de)
		{
			this.deStar.Add(de);
		}

		public DirectedEdgeStar OutEdges
		{
			get
			{
				return this.deStar;
			}
		}

		public int Degree
		{
			get
			{
				return this.deStar.Degree;
			}
		}

		public int GetIndex(Edge edge)
		{
			return this.deStar.GetIndex(edge);
		}

		public void Remove(DirectedEdge de)
		{
			this.deStar.Remove(de);
		}

		internal void Remove()
		{
			this.pt = null;
		}

		public override bool IsRemoved
		{
			get
			{
				return this.pt == null;
			}
		}

		public override string ToString()
		{
			return string.Concat(new object[]
			{
				"NODE: ",
				this.pt,
				": ",
				this.Degree
			});
		}

		protected Coordinate pt;

		protected DirectedEdgeStar deStar;
	}
}
